{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "project_info = pd.read_csv('corr.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "class_info = pd.read_csv('corr_sample.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "pm = {}\n",
    "for i in range(project_info.count()['project']):\n",
    "    pm[project_info.loc[i, :]['project']] = project_info.loc[i, :].to_dict()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "class_info['cp'] = class_info['project'].apply(lambda x:pm[x]['cp'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#class_info.to_csv('corr_object_info.csv', index=False, columns=['project', 'TARGET_CLASS', 'cp'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>search_budget</th>\n",
       "      <th>Total_Goals</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>20.000000</td>\n",
       "      <td>20.0</td>\n",
       "      <td>20.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>34.750000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>164.100000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>36.868008</td>\n",
       "      <td>0.0</td>\n",
       "      <td>142.714621</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>52.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>6.500000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>73.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>21.500000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>118.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>52.500000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>201.500000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>129.000000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>629.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               id  search_budget  Total_Goals\n",
       "count   20.000000           20.0    20.000000\n",
       "mean    34.750000            5.0   164.100000\n",
       "std     36.868008            0.0   142.714621\n",
       "min      0.000000            5.0    52.000000\n",
       "25%      6.500000            5.0    73.500000\n",
       "50%     21.500000            5.0   118.500000\n",
       "75%     52.500000            5.0   201.500000\n",
       "max    129.000000            5.0   629.000000"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class_info.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'class': 'org.asynchttpclient.spnego.SpnegoEngine', 'branch': 75, 'project': 'async-http-client'}, {'class': 'org.asynchttpclient.uri.UriParser', 'branch': 154, 'project': 'async-http-client'}, {'class': 'org.asynchttpclient.config.AsyncHttpClientConfigDefaults', 'branch': 55, 'project': 'async-http-client'}, {'class': 'org.asynchttpclient.ntlm.NtlmEngine', 'branch': 195, 'project': 'async-http-client'}, {'class': 'com.github.kevinsawicki.http.HttpRequest', 'branch': 423, 'project': 'http-request'}, {'class': 'org.joda.time.Partial', 'branch': 140, 'project': 'joda-time'}, {'class': 'org.joda.time.LocalDateTime', 'branch': 228, 'project': 'joda-time'}, {'class': 'org.joda.time.PeriodType', 'branch': 119, 'project': 'joda-time'}, {'class': 'org.joda.time.LocalDate', 'branch': 221, 'project': 'joda-time'}, {'class': 'org.json.Cookie', 'branch': 65, 'project': 'JSON-java'}, {'class': 'org.json.JSONTokener', 'branch': 139, 'project': 'JSON-java'}, {'class': 'org.json.JSONObject', 'branch': 629, 'project': 'JSON-java'}, {'class': 'org.json.JSONWriter', 'branch': 84, 'project': 'JSON-java'}, {'class': 'org.json.XML', 'branch': 269, 'project': 'JSON-java'}, {'class': 'org.jsoup.nodes.TextNode', 'branch': 53, 'project': 'jsoup'}, {'class': 'org.jsoup.nodes.Node', 'branch': 118, 'project': 'jsoup'}, {'class': 'org.jsoup.safety.Whitelist', 'branch': 101, 'project': 'jsoup'}, {'class': 'org.jsoup.helper.DataUtil', 'branch': 52, 'project': 'jsoup'}, {'class': 'spark.route.SimpleRouteMatcher', 'branch': 93, 'project': 'spark'}, {'class': 'spark.utils.MimeParse', 'branch': 69, 'project': 'spark'}]\n"
     ]
    }
   ],
   "source": [
    "class_list = []\n",
    "class_info.apply((lambda x : class_list.append({'class':x['TARGET_CLASS'], 'branch':x['Total_Goals'], 'project':x['project']})), axis=1)\n",
    "print(class_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from jinja2 import Environment, PackageLoader, select_autoescape, FileSystemLoader\n",
    "env = Environment(\n",
    "     loader=FileSystemLoader(\"paper/templates\"),\n",
    "    autoescape=select_autoescape()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "template = env.get_template(\"corr-projects.tex.tpl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "print(template.stream(classes=class_list).dump('paper/corr-projects.tex'))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
